/**
 * @description ip与long整型的互转
 * @author xujs
 */

function int2ip(ip_int) {
	const i = ip_int
	const iv = (ip) => (ip >>> 24)
	const result = [0, 8, 16, 24]
	return result.map(r => iv(i << r)).join('.')
}


function ip2int(ip_str) {
    const type = Object.prototype.toString.call(ip_str)
    if (type !== '[object Array]') {
      ip_str = ip_str.split('.')
    }
    if (ip_str.length !== 4) return 0
    ip_str = ip_str.map(i => Number(i))
    if (ip_str.find(i => i < 0 || i > 255)) return 0
    const t = (prev, cur) => prev * Number(1 << 8) + cur
    return ip_str.reduce(t, Number(0))
}


export {
	int2ip,
	ip2int
}